var t = getApp(), a = require("../../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ a ],
    data: {
        startTime: "",
        endtTime: "",
        list: [],
        customer_details: [],
        display_set: [],
        isLoadMore: !0,
        total_page: 0,
        page: 1
    },
    onLoad: function(t) {
        var a = this.formatTimes(new Date());
        this.setData({
            startTime: a,
            endtTime: this.formatTimes(this.getlastMonth())
        }), wx.setNavigationBarTitle({
            title: "轨迹追踪"
        }), t.id && this.setData({
            id: t.id
        }), this.getData();
    },
    confirm: function(t) {
        console.log(t), this.setData({
            endtTime: t.detail.value
        }), this.init(), this.getData();
    },
    confirm_end: function(t) {
        this.setData({
            startTime: t.detail.value
        }), this.init(), this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {},
    telCall: function(t) {
        var a = t.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    clearTime: function() {
        this.setData({
            endtTime: "",
            startTime: ""
        }), this.init(), this.getData();
    },
    init: function() {
        this.setData({
            page: 1,
            total_page: 0,
            isLoadMore: !0,
            list: []
        });
    },
    onCopyWechat: function(t) {
        var a = t.currentTarget.dataset.wechat;
        wx.setClipboardData({
            data: a,
            success: function() {
                wx.hideToast(), wx.showModal({
                    content: "复制微信号成功",
                    showCancel: !1
                });
            }
        });
    },
    isUrl: function(t) {
        return !/^((https|http):\/\/).+$/g.test(t);
    },
    onCopy: function(t) {
        var a = t.currentTarget.dataset.url;
        this.isUrl(a) ? wx.navigateTo({
            url: "/" + a
        }) : wx.setClipboardData({
            data: "data",
            success: function() {
                wx.hideToast(), wx.showModal({
                    content: "已经复制链接，请在微信聊天窗口中发送后点击打开！",
                    showCancel: !1
                });
            }
        });
    },
    formatTimes: function(t) {
        var a = t.getFullYear(), e = t.getMonth() + 1, s = t.getDate();
        t.getHours(), t.getMinutes(), t.getSeconds();
        return [ a, e, s ].map(this.formatNumber).join("-");
    },
    formatNumber: function(t) {
        return (t = t.toString())[1] ? t : "0" + t;
    },
    getlastMonth: function() {
        var t = new Date(), a = t.getDate(), e = new Date(t.getTime());
        e.setMonth(e.getMonth()), e.setDate(0);
        var s = e.getDate();
        return e.setDate(a > s ? s : a), console.log(e), e;
    },
    getData: function() {
        var a = this, e = {
            member_id: this.data.id
        };
        this.data.endtTime && (e.start_date = this.data.endtTime), this.data.startTime && (e.end_date = this.data.startTime);
        var s = t.getNetAddresss("plugin.customer-center.frontend.controllers.browse.get-member-browse-details");
        t._postNetWork({
            url: s,
            data: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.data.isLoadMore = !0, a.data.total_page = e.data.browse_details_list.last_page, 
                a.data.total_page || (a.data.total_page = 0), a.setData({
                    customer_details: e.data.customer_details,
                    list: e.data.browse_details_list.data,
                    display_set: e.data.display_set
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var a = this, e = "";
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            var s = {
                member_id: this.data.id
            };
            this.data.endtTime && (s.start_date = this.data.endtTime), this.data.startTime && (s.end_date = this.data.startTime), 
            this.data.page = this.data.page + 1, s.page = this.data.page, e = t.getNetAddresss("plugin.customer-center.frontend.controllers.browse.get-member-browse-details"), 
            t._postNetWork({
                url: e,
                data: s,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (a.data.isLoadMore = !0, a.setData({
                        list: a.data.list.concat(e.data.browse_details_list.data)
                    })) : (a.data.page = a.data.page - 1, a.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    }
});